/**
 * 优先级队列
 */
;(function(window, document){
	var PriorityQueue = function(pIntMaxSize){
		this._maxSize = pIntMaxSize;
		this._datas = [];
		this._length = 0;
	};
	PriorityQueue.prototype = {
		constructor: PriorityQueue,
		enque: function(pData){
			if( this.isFull() ) throw new Error('优先队列已满');
			this._datas[this._length++] = pData;
			if( this._length == 0 ) return;
			for( var i= this._length-1; i>0; i--){
				if( this._datas[i] < this._datas[i-1] ){
					var tmp = this._datas[i];
					this._datas[i] = this._datas[i-1];
					this._datas[i-1] = tmp;
				}else break;
			}
		},
		deque: function(){
			if( this.isEmpty() ) throw new Error('优先队列为空');
			return this._datas[--this._length];
		},
		isEmpty: function(){
			return this._length == 0;
		},
		isFull: function(){
			return this._length == this._maxSize;
		},
		getSize: function(){
			return this._length;
		},
		toString: function(){
			return '['+this._datas.join(',')+']';
		}
	};

	window.PriorityQueue = PriorityQueue;
})(window, document);